package com.ruoyi.common.tcp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


@Component
public class NettyConfig {

    private static Logger log = LoggerFactory.getLogger(NettyConfig.class);


    /**
     * 初始化连接
     * 查询数据库表中所有host和port不为空的设备
     * netty客户端尝试连接并保存至channels内存中
     */
    @PostConstruct
    public void getDeviceWarterInfo() {
        try {
            List<Map<String, Object>> serverList = new ArrayList<>();
            /*Map<String, Object> tcpServer1 = new HashMap<>();
            tcpServer1.put("IP","192.168.1.9");
            tcpServer1.put("PORT","8234");
            serverList.add(tcpServer1);*/
            Map<String, Object> tcpServer2 = new HashMap<>();
            tcpServer2.put("IP","192.168.1.7");
            tcpServer2.put("PORT","8234");
            serverList.add(tcpServer2);
            NettyClient.channels = NettyClient.getChannel(serverList);

        }catch (Exception e) {
            e.printStackTrace();
        }

    }

}
